package gandalf;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class PersistenceManager {

    private static EntityManagerFactory emf;

    public static EntityManagerFactory getInstance() {
        if (emf == null) {
            emf = Persistence.createEntityManagerFactory("GandalfPU");
        }

        return emf;
    }

    public static EntityManager createEntityManager() {
        return getInstance().createEntityManager();
    }

    public boolean isOpen() {
        return emf.isOpen();
    }

    public void close() {
        emf.close();
    }
}
